package ldk.easytouch.activity;

import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;

import ldk.easytouch.helper.InstrumentHelper;
import ldk.easytouch.helper.PositionHelper;
import ldk.easytouch.utils.ETLog;

/**
 * Created by ldkxingzhe on 2016/9/14.
 */
public abstract class AbstractMenuActivity extends BaseActivity{
    @SuppressWarnings("unused")
    private static final String TAG = "AbstractMenuActivity";

    @Override
    public boolean onUpdateWindowLayoutParams(WindowManager.LayoutParams params) {
        ETLog.v(TAG, "onUpdateWindowLayoutParams");
        setFlagTouchableOutSide(params);
        Rect rect = adjustCenter(params);
        ScaleAnimation animation = new ScaleAnimation(0f, 1f, 0f, 1f, rect.width() / 2, rect.height() / 2);
        animation.setInterpolator(new AccelerateDecelerateInterpolator());
        animation.setDuration(500);
        getContentView().startAnimation(animation);
        getContentView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        return true;
    }

    @Override
    public void finish() {
        ScaleAnimation animation = new ScaleAnimation(1f, 0f, 1f, 0f,
                getContentView().getMeasuredWidth()/2, getContentView().getMeasuredHeight()/2);
        animation.setInterpolator(new AccelerateDecelerateInterpolator());
        animation.setDuration(300);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                ETLog.v(TAG, "finish Animation end");
                AbstractMenuActivity.super.finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        getContentView().startAnimation(animation);
    }
}
